#pragma once

#include "GameApplication.h"
#include "CameraNode.h"
#include "LightNode.h"
#include "Entity.h"
#include "ITask.h"

class GameEditorGUI;

class GameEditor
{
public:
	GameEditor( Pointer<ITask>& timer, Pointer<ITask>& physics, Pointer<ITask>& update, Pointer<ITask>& combat );

	void AddSpawnPointBehavior( Entity* selected );
	void AddMinionBehavior( Entity* selected );

	void CreateEntity();
	void CreateLight();
	void CreateAI();
	bool CreateTerrain( const std::string& filename, const std::string& name, const unsigned int pixelStep, const std::vector<std::string>& textures );
	void CreateWorld( HashedString name );
		
	Entity* getSelected();
	void Select( Entity* entity );
	IEntityController* FindController();
	IEntityController* FindController( Entity* entity );
	void AddRigidBodyShape( HashedString type, float x, float y, float z );
	void DeleteAllRigidBodyShapes( Entity* selected );
	void DeleteRigidBodyShape( Entity* selected, unsigned int shape );
	void AddSelectableBodyShape( HashedString type, float x, float y, float z );
	void DeleteAllSelectableBodyShapes( Entity* selected );
	void DeleteSelectableBodyShape( Entity* selected, unsigned int shape );
	
	static bool LoadTexture( std::string filename );
	bool LoadModel( std::string fileName, std::string& modelName );
	void SaveGameState( std::string filename );
	void LoadGameState( std::string filename );
	void SetEntityGraphic( Entity* selected, HashedString name );
	void SetEntityName( Entity* selected, HashedString name );
	void SetEntityPosition( Entity* selected, float x, float y, float z );
	bool SetEntityWorld( Entity* selected, HashedString name );
	void SetLightPosition(Pointer<LightNode>& light, float x, float y, float z);
	
	void RemoveEntity( HashedString name );
	void RemoveEntity( Entity* entity );

	void ToggleAddDestinationFlag();
	bool ReceiveEvent( IEvent& event );
	void AddDestination( int x, int y );
	void SelectEntity( int x, int y );

	void Run();
	void Stop();
	void EnterRunningGameState();
	void ExitRunningGameState();
	void setTimer( Pointer<ITask>& timer );
	void setPhysics( Pointer<ITask>& physics );
	void setUpdate( Pointer<ITask>& update );
	void setCombat( Pointer<ITask>& combat );
protected:
	bool m_addingDestinationFlag;
	bool m_inRunningGameState;
	Time m_toggleTimer;
	bool m_running;
	Pointer<GameEditorGUI> m_gameEditorGUI;
	Pointer<ITask> m_timer;
	Pointer<ITask> m_physics;
	Pointer<ITask> m_updates;
	Pointer<ITask> m_combat;
	Pointer<CameraNode> m_cameraNode;
	unsigned int m_entityCounter;
	Entity* m_selected;
};